/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.imob.modelo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Gilton Nascimento
 */
@Entity
@Table(name = "\"OBRA\"", catalog = "imob", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Obra.findAll", query = "SELECT o FROM Obra o"),
    @NamedQuery(name = "Obra.findByObraId", query = "SELECT o FROM Obra o WHERE o.obraId = :obraId"),
    
    @NamedQuery(name = "Obra.findByObra", query = "SELECT o FROM Obra o WHERE o.obra = :obra"),
    @NamedQuery(name = "Obra.findLikeByObra", query = "SELECT o FROM Obra o WHERE o.obra Like :obra"),
    
    @NamedQuery(name = "Obra.findByDataInicio", query = "SELECT o FROM Obra o WHERE o.dataInicio = :dataInicio"),
    @NamedQuery(name = "Obra.findByDataTermino", query = "SELECT o FROM Obra o WHERE o.dataTermino = :dataTermino")})
public class Obra extends ControlEntities implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
//  <editor-fold defaultstate="collapsed" desc="Geradores de Sequencias">
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
    @SequenceGenerator(name = "SEQ_STORE", sequenceName = "next_obra")// </editor-fold>
    @Basic(optional = false)
    @Column(name = "obra_id", nullable = false)
    private Integer obraId;
    @Basic(optional = false)
    @Column(name = "obra", nullable = false, length = 2147483647)
    private String obra;
    @Column(name = "data_inicio")
    @Temporal(TemporalType.DATE)
    private Date dataInicio;
    @Column(name = "data_termino")
    @Temporal(TemporalType.DATE)
    private Date dataTermino;
    @OneToMany(mappedBy = "obra", fetch = FetchType.LAZY)
    private List<Empresa> empresaList;
    @OneToMany(mappedBy = "obra", fetch = FetchType.LAZY)
    private List<Construtora> construtoraList;

    public Obra() {
    }

    public Obra(Integer id) { this.obraId = id; }

    public Obra(String obr) { obra = obr; }
    
    public Obra(Integer obraId, String obra) {
        this.obraId = obraId;
        this.obra = obra;
    }
    
    public Obra(Integer id, String typeDt, String data) {
    	obraId = id;
    	if ( typeDt.equals("dataInicio") )
    		dataInicio = str2Date(data);
    	else if ( typeDt.equals("dataTermino") )
    		dataTermino = str2Date(data);
    }
    
    public Obra(Integer id, String obr, String typeDt, String data) {
    	this(id, typeDt, data);
    	obra = obr;
    }

    
//    Getts and Setts
	public Integer getObraId() {
        return obraId;
    }

    public void setObraId(Integer obraId) {
        this.obraId = obraId;
    }

    public String getObra() {
        return obra;
    }

    public void setObra(String obra) {
        this.obra = obra;
    }

    public Date getDataInicio() {
        return dataInicio;
    }

    public void setDataInicio(Date dataInicio) {
        this.dataInicio = dataInicio;
    }

    public Date getDataTermino() {
        return dataTermino;
    }

    public void setDataTermino(Date dataTermino) {
        this.dataTermino = dataTermino;
    }

    public List<Empresa> getEmpresaList() {
        return empresaList;
    }

    public void setEmpresaList(List<Empresa> empresaList) {
        this.empresaList = empresaList;
    }

    public List<Construtora> getConstrutoraList() {
        return construtoraList;
    }

    public void setConstrutoraList(List<Construtora> construtoraList) {
        this.construtoraList = construtoraList;
    }
    
    public Object[] getValues() {
    	Object[] objects = {obraId, obra, dataInicio, dataTermino};
    	return objects; 
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (obraId != null ? obraId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Obra)) {
            return false;
        }
        Obra other = (Obra) object;
        if ((this.obraId == null && other.obraId != null) || (this.obraId != null && !this.obraId.equals(other.obraId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.imob.modelo.Obra[obraId=" + obraId + "]";
    }

}
